Rand()

Math Function

Syntax samples

RAND(<expression>)

RAND(10) min

ORDER RAND(10) EntA TO Loc1

IF RAND(100) > 45 THEN ROUTE 1

Description

Returns a random value n between 0 and X (0 <= n < X) where X is the result of the expression.

To generate random numbers between the expression and a number other than zero use the expression as the range between the maximum and minimum values. Then add the minimum to the random number. For example, the statement Attr1 = 2+RAND(3) generates a random number from two up to, but not including, five. An alternate method is to use a uniform distribution. Note that the RAND() function works very similar to a uniform distribution. For more information on Distributions, see Distribution Functions.

This function returns a real number, although the real value may be converted to an integer. To have the RAND() function generate random integer values between zero and some upper bound, use the formula, Integer_Value = RAND(X+1), where X is the greatest integer that should be returned by the function. For example, to generate a random integer value between zero and six, use the formula, Integer_Value = RAND(7). The RAND(7) part of this formula will actually generate a real value between 0 and 6.999, but will be truncated to a whole number between 0 and 6 when assigned to an integer value. Therefore, when generating integer values, make sure that the result of the RAND() function is assigned to an integer value, or is used in an expression where it will be truncated to an integer.

Valid In

Any expression.

Components

<expression>

The upper limit of the random value to return. This value will never be returned.

Example

Two resources, Oper_1 and Oper_2, perform the same task at a location, Press. Oper_1 works at several other locations. As a result, Press only uses him 30% of the time. The other 70% of the time, Oper_2 performs the task.

Process Table

Entity

Location

Operation (min)

Axle

Press

IF RAND(100) < 30 THEN

USE Oper_1

ELSE USE Oper_2

Routing Table

Blk

Output

Destination

Rule

Move Logic

1

Axle

Lather

FIRST 1

MOVE FOR 3

See Also

Streams.